from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
import time
# 已取消订单的订单号
testCase="DBshop006_订单管理删除订单"
rootPath=get_pro_rootpath()
filePath=rootPath+"\public\order004.txt"
orderID=readFile(filePath)
# 1.点击销售管理订单管理界面。
firefox=openBrowser(urlAdmin)
DBshopLoginAdmin(firefox)
DBshopEnterMenu2(firefox, "销售管理", "订单管理")
# 2.在订单状态点击已取消一栏，点击“搜索”按钮一款，勾选之后，选择删除，点击提交操作。
firefox.find_element_by_xpath("//select[@id='order_state']/option[2]").click()
firefox.find_element_by_xpath("//button[@class='btn btn-small btn-primary']").click()
firefox.find_element_by_xpath(
    "//td[text()='%s']/following-sibling::td[7]/a[text()='编辑查看']" % orderID).click()
firefox.find_element_by_partial_link_text("删除订单").click()
firefox.switch_to.alert.accept()
# 3.删除成功
time.sleep(2)
firefox.find_element_by_xpath("//input[@name='order_sn']").send_keys(orderID)
firefox.find_element_by_xpath("//button[contains(.,'搜索')]").click()
time.sleep(2)
# 断言
string=firefox.find_element_by_xpath("//body").text
l="\(订单数："
r="\)"
text=reGetString(string,l,r)
if text=="0":
    writeLog("%s 测试通过"%testCase)
else:
    writeLog("%s 测试失败"%testCase)
    getPhoto(firefox)
firefox.quit()